package com.pignest.hotel.system;

import java.util.Date;

import org.zkoss.zk.ui.util.Clients;

import bsh.util.Util;

import com.pignest.framework.util.Utils;
import com.pignest.hotel.beans.HotelBill;
import com.pignest.hotel.beans.Living;
import com.pignest.hotel.beans.Room;
import com.pignest.hotel.beans.TbCloseAccounts;
import com.pignest.hotel.beans.User;
import com.pignest.hotel.definition.BillType;
import com.pignest.hotel.definition.OpenRoomType;
import com.pignest.hotel.definition.PayMethod;
import com.pignest.hotel.service.IncomeService;
import com.pignest.hotel.service.ReceptionService;
import com.pignest.hotel.spring.Services;
import com.pignest.hotel.util.DateUtil;
@Deprecated
public class PrintLODOP {
	
	private IncomeService incomeService;
	private ReceptionService receptionService;
	public PrintLODOP()
	{
		incomeService=Services.getIncomeService();
		receptionService =Services.getReceptionService();
	}
    
    public void printCheck(){
    	
    }
	public void print(Living l)
	{
		Room room =l.getRoom();
		Date liveDate =l.getLiveTime();
		String orderNo=DateUtil.toString(liveDate,"yyyyMMddHHmmss");
		String roomName =room.getName();
		String roomType =room.getType().getName();
		String discount=Utils.toPrice(l.getAdjustPrice());
		String name =l.getCustormName();
		String sLiveTime=DateUtil.toString(liveDate,"yyyy-MM-dd HH:mm:ss");
		String sLeaveTime=DateUtil.toString(l.getLeaveDate(),"yyyy-MM-dd HH:mm:ss");
		String days =String.valueOf(incomeService.queryCheckOutDays(l,true,null));
		//String deposit =Utils.toPrice(receptionService.querySingleDeposit(l));//押金
		String deposit =Utils.toPrice(incomeService.countAllDeposit(l, true));
		int rent =incomeService.countRoomConsums(l, true);//房费
		String sRent =Utils.toPrice(rent);
		int cost =incomeService.countOtherConsums(l,true);//其它消费，不包括房费
		String sCost =Utils.toPrice(cost);
		//查询总消费情况为项目为所有负数的情况
		int accounts =incomeService.countAllConsumsUsed(l, true,null);
		String sAccounts =Utils.toPrice(accounts);
		int refundment =incomeService.countBalance(l, true);//余额
		String sRefundment =Utils.toPrice(refundment);
		TbCloseAccounts ca = receptionService.queryLastCloseAccount(l);
		String paymentMethod="";
		if(ca!=null){
			PayMethod pm =PayMethod.valueOf(ca.getType());
			paymentMethod =pm.getDisplayName();
		}
		User user =Hotel.getCurrentUser();
		String userName =user.getName();
		String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		Clients.evalJavaScript("check('"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+days+"','"
				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"+curTime+"');");
	}	
	public void printLiving(Living l)
	{
		Room room =l.getRoom();
		Date liveDate =l.getLiveTime();
		String orderNo=DateUtil.toString(liveDate,"yyyyMMddHHmmss");
		String roomName =room.getName();
		String roomType =room.getType().getName();
		String discount=Utils.toPrice(l.getAdjustPrice());
		String name =l.getCustormName();
		String sLiveTime=DateUtil.toString(liveDate,"yyyy-MM-dd HH:mm:ss");
		String deposit =Utils.toPrice(incomeService.countAllDeposit(l, false));
		String cerType =l.getPassportType();
		String cerNo =l.getPassportNumber();
		String roomPrice =Utils.toPrice(l.getRoomPrice());
		String oType=OpenRoomType.valueof(l.getOpenRoomType()).getDisplayName();
		User user =Hotel.getCurrentUser();
		String userName =user.getName();
		String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		Clients.evalJavaScript("livingPrint('"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"
				+deposit+"','"+cerType+"','"+cerNo+"','"+userName+"','"+curTime+"','"+roomPrice+"','"+oType+"')");
	}
	public void comeLiving(Living l,int comeOnMoney)
	{
		Room room =l.getRoom();
		Date liveDate =l.getLiveTime();
		String orderNo=DateUtil.toString(liveDate,"yyyyMMddHHmmss");
		String roomName =room.getName();
		String roomType =room.getType().getName();

		String name =l.getCustormName();
		String sLiveTime=DateUtil.toString(liveDate,"yyyy-MM-dd HH:mm:ss");
		String deposit =Utils.toPrice(comeOnMoney);

		User user =Hotel.getCurrentUser();
		String userName =user.getName();
		String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		Clients.evalJavaScript("comeOnPrint('"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
				+deposit+"','"+userName+"','"+curTime+"')");
	}
	public void printCheck(HotelBill b)
	{
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		int adjustPrice =b.getAdjustPrice();
		String discount =Utils.toPrice(adjustPrice);
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		float count =b.getLiveCount();
		String open =b.getOpenType();
		String sCount ="";
		if(OpenRoomType.HOURS.name().equals(open))
		{
			sCount=count+"小时";
		}else{
			sCount =count+"天";
		}
		String deposit =Utils.toPrice(b.getDeposit());
		String sLeaveTime =DateUtil.toString(b.getLeaveTime(),"yyyy-MM-dd HH:mm:ss");
		String sRent =Utils.toPrice(b.getRent());
		String sCost =Utils.toPrice(b.getCost());
		String sAccounts =Utils.toPrice(b.getAccounts());
		String sRefundment =Utils.toPrice(b.getRefundment());
		String paymentMethod=PayMethod.valueOf(b.getPayment()).getDisplayName();
        String userName =b.getOperator();
        String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		Clients.evalJavaScript("check('"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+sCount+"','"
				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"+curTime+"');");
	}
}
